<?php

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

?><?=$filterBlock->create('Filter', array('url'=>("/{$url_part}/")));?><?php
	$filterBlock->add(
        $form->label('from_date', __d($po_domain, 'created_field', true).': '.mb_strtolower(__d(null, 'from_period', true), DEFAULT_CHARSET).' ',array('class'=>'filter')).
		$calendar->date('from_date', false, array('size' => '10', 'label' => false)).
        ' '.
		$form->label('to_date', __d(null,'to_period', true).' ',array('class'=>'filter')).
		$calendar->date('to_date', false, array('size' => '10', 'label' => false))
	);
	$filterBlock->add(
        $form->label('searche', __d(null, 'searche_filter', true).': ', array('class'=>'filter')).
		$form->text('searche', false, array('size' => '17', 'label' => false))
	);
?><?=$filterBlock->end();?><?php

?><br /><?php

if (count($list->rows)) {

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'name', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'contract', 'domain' => $po_domain));?><?php
        ?></th><?php
        /*?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'contract_start_date', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'contract_finish_date', 'domain' => $po_domain));?><?php
        ?></th><?php*/
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'reg_code', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'tools', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'contact_person', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'balance', 'msg' => 'balance/free', 'domain' => $po_domain));?><?php
        ?></th><?php
        ?><th class="actions nw"></th><?php
    ?></tr><?php
?></thead><?php
?><tbody><?php

    vendor('date');
    $i = 0;
    foreach ($list->rows as $item) {
        $class = '';
    	if ($i++ % 2 != 0) {
    		$sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
    		?><td class="nw"><?php
                ?><?=$html->link($item[$modelName]['name'], "/clients/{$item[$modelName][$PKName]}/candidates", array('escape'=>false));?><?php
            ?></td><?php
    		?><td class="nw"><?php
                if (!empty($item[$modelName]['contract'])) {
                    $start_date_caption = __d($po_domain, 'contract_start_date', true);
                    $start_finish_caption = __d($po_domain, 'contract_finish_date', true);
                    $start_date = !empty($item[$modelName]['contract_start_date']) ? Date::Short(Date::SQL2UNIX($item[$modelName]['contract_start_date']), false) : '—';
                    $finish_date = !empty($item[$modelName]['contract_finish_date']) ? Date::Short(Date::SQL2UNIX($item[$modelName]['contract_finish_date']), false) : '—';
                    $hint = $start_date_caption.': '.$start_date;
                    $hint .= "&#13;";
                    $hint .= $start_finish_caption.': '.$finish_date;
                    ?><span title="<?=($hint);?>" class="hinteble"><?php
                        ?><?=($item[$modelName]['contract']);?><?php
                    ?></span><?php
                } else {
                    ?>—<?php
                }
            ?></td><?php
            /*?><td class="nw"><?php
                if (!empty($item[$modelName]['contract_start_date'])) {
                    ?><?=Date::Short(Date::SQL2UNIX($item[$modelName]['contract_start_date']), false);?><?php
                } else {
                    ?>—<?php
                }
            ?></td><?php
            ?><td class="nw"><?php
                if (!empty($item[$modelName]['contract_finish_date'])) {
                    ?><?=Date::Short(Date::SQL2UNIX($item[$modelName]['contract_finish_date']), false);?><?php
                } else {
                    ?>—<?php
                }
            ?></td><?php*/
            ?><td class="nw"><?php
                ?><?=($item[$modelName]['reg_code']);?><?php
            ?></td><?php
            ?><td class=""><?php
                if (!empty($item[$modelName]['tools'])) {
                    $str = array();
                    foreach ($tools_list as $k => $v) {
                        if (in_array($k, $item[$modelName]['tools'])) {
                            $str[] = '<span class="nw">'.h($v).'</span>';
                        }
                    }
                    ?><?=implode(', ', $str);?><?php
                } else {
                    ?>—<?php
                }
                /*
                ?><br /><?php
                ?><?=$html->link(__d($po_domain, 'change_tools', true), "/clients/{$item[$modelName][$PKName]}/tools");?><?php
                */
            ?></td><?php
            ?><td class="nw"><?php
                ?><?=($item[$modelName]['contact_person_name']);?><?php
                if (!empty($item[$modelName]['contact_person_city'])) {
                    ?><br /><?php
                    ?><?=($item[$modelName]['contact_person_city']);?><?php
                }
                if (!empty($item[$modelName]['contact_person_tel'])) {
                    ?><br /><?php
                    ?><?=($item[$modelName]['contact_person_tel']);?><?php
                }
                if (!empty($item[$modelName]['contact_person_email'])) {
                    ?><br /><?php
                    ?><?=($item[$modelName]['contact_person_email']);?><?php
                }
            ?></td><?php
            ?><td class="nw"><?php
                ?><div class="align-r"><?php
                ?><?=$this->renderElement('sum', array('sum'=>$item[$modelName]['balance']));?><?php
                ?></div><?php
                ?><?=$html->link(__d($po_domain, 'view_log', true), "/clients/{$item[$modelName][$PKName]}/billing");?><?php
                ?><br /><?php
                ?><?=$html->link(__d($po_domain, 'refill_account', true), "/clients/{$item[$modelName][$PKName]}/refill");?><?php
            ?></td><?php
            ?><td class="actions"><?php
                ?><table class="sys_clear" cellpadding="0"><?php
                ?><tr class="sys_clear"><?php
                    ?><?=$ehtml->iconLink("admins", __d($po_domain, 'admins', true), "/clients/{$item[$modelName][$PKName]}/admins");?><?php
                    ?><?=$ehtml->iconLink("edit", __d(null, $item[$modelName]['__allows']['update'] ? 'change' : 'view', true), "/{$url_part}/{$item[$modelName][$PKName]}/");?><?php
                    $inactive = !($item[$modelName]['__allows']['delete']);
                    $inactive_str = $inactive ? __d(null, 'deny', true) : false;
                    if (!$inactive) {
                        ?><?=$ehtml->iconLink("cancel", __d(null, 'delete', true), "/{$url_part}/{$item[$modelName][$PKName]}/delete", array('inactive' => $inactive_str,), __d($po_domain, 'confirm_del', true)." ".__d(null, "open_q1", true).$item[$modelName]['name'].__d(null, "close_q1", true)."?");?><?php
                    }
                ?></tr><?php
                ?></table><?php
            ?></td><?php
    	?></tr><?php
    }

?></tbody><?php
?></table><?php

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d($po_domain, 'List is empty', true);?><?php
    ?></span><?php
}

?>